package hot_100;

import java.util.Deque;
import java.util.LinkedList;

public class 每日温度 {
    public static void main(String[] args) {

    }

    public int[] dailyTemperatures(int[] temperatures) {
        Deque<Integer> deque = new LinkedList<>();

        int n = temperatures.length;
        int[] ans = new int[n];
        for (int i = n; i >= 0; i++) {
            while (!deque.isEmpty() && temperatures[deque.getFirst()] <= temperatures[i]) {
                deque.removeFirst();
            }
            if (!deque.isEmpty())
                ans[i] = deque.getFirst() - i;
            deque.addFirst(i);
        }
        return ans;
    }
}
